<template>
  <div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="ID" width="180"></el-table-column>
      <el-table-column prop="username" label="用户名" width="180"></el-table-column>
      <el-table-column prop="email" label="邮箱" width="180"></el-table-column>
      <el-table-column prop="phone" label="电话" width="180"></el-table-column>
      <el-table-column label="注册时间" width="180">
        <template slot-scope="scope">{{scope.row.updateTime | filTime}}</template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 6, 7, 8]"
      :page-size="pageSize"
      layout="sizes, prev, pager, next"
      :total="1000"
    ></el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      pageSize: 5,
      currentPage: 1,
    };
  },
  filters: {
    filTime(time) {
        console.log(time)
        var time = new Date(time);
        function timeAdd0(str) {
        if (str < 10) {
          str = '0' + str;
        }
        return str
        }
        var y = time.getFullYear();
        var m = time.getMonth() + 1;
        var d = time.getDate();
        var h = time.getHours();
        var mm = time.getMinutes();
        var s = time.getSeconds();
        return y + '-' + timeAdd0(m) + '-' + timeAdd0(d) + '' + timeAdd0(h) + ':' + timeAdd0(mm) + ':' + timeAdd0(s);
    },
  },
  mounted() {
    var obj = {
      pageSize: this.pageSize,
      pageNum: this.currentPage,
    };
    this.$network.getUser(obj).then((res) => {
      console.log(res.data.data.list);
      this.tableData = res.data.data.list;
      this.tableData.forEach((ele) => {
        var date = new Date(parseInt(ele.createTime) * 1000);
        ele.date = `${date.getFullYear()}-${date.getMonth()}-${date.getDay()}`;
      });
    });
  },
  methods: {
    handleSizeChange(val) {
      this.pageSize = val;
      var obj = {
        pageNum: this.currentPage,
        pageSize: this.pageSize,
      };
      this.$network.getUser(obj).then((res) => {
        this.tableData = res.data.data.list;
        this.tableData.forEach((ele) => {
          var date = new Date(parseInt(ele.createTime) * 1000);
          ele.date = `${date.getFullYear()}-${date.getMonth()}-${date.getDay()}`;
        });
      });
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      var obj = {
        pageNum: this.currentPage,
        pageSize: this.pageSize,
      };
      this.$network.getUser(obj).then((res) => {
        this.tableData = res.data.data.list;
        this.tableData.forEach((ele) => {
          var date = new Date(parseInt(ele.createTime) * 1000);
          ele.date = `${date.getFullYear()}-${date.getMonth()}-${date.getDay()}`;
        });
      });
    },
  },
};
</script>

<style>
</style>